<?php
/*
 * @Date: 2021-02-03 22:10:31
 * @名称: author_and_chinese_team 操作控制器
 * @版本: 0.01
 * @作者: 初雪桜
 * @邮箱: 202184199@qq.com
 * @最后编辑: 初雪桜
 * @LastEditTime: 2021-02-03 23:26:33
 * @FilePath: /Site/app/useradmin/controller/DataBaseController/AuthorAndChineseTeam.php
 */

namespace app\useradmin\controller\DataBaseController;

use app\BaseController;
use think\facade\Db;

class AuthorAndChineseTeam extends BaseController
{
    public function Select($UserId, $BookId, $Permission = ['certification_time', 'add_time', 'rand_str'])
    {
        array_push($Permission, 'state');
        $return_data = Db::table('author_and_chinese_team')
            ->where([
                "book_id" => $BookId,
                "user_id" => $UserId,
            ])
            ->field($Permission)
            ->select();
        if (count($return_data) != 1) {
            $return_data = errorJsonReturn('The user has appeared here multiple times', '数据信息异常 请联系管理员解决');
        } else {
            $return_data = successJsonReturn($return_data[0]);
        }
        $return_data = json_decode($return_data->getContent(), true);
        return $return_data;
    }
    /**
     * @方法名: 修改用户权限 author_and_chinese_team
     * @作者: 初雪桜
     * @信息: 更新 author_and_chinese_team 表的权限
     * @param String $UserId 用户id
     * @param String $BookId 书籍id
     * @param String $_id 表id
     * @param {*} $NewParameters 要设置的权限信息
     * @param {*} $quick 快速设置 设置全部权限
     * @return {*}
     */
    public function Update($UserId, $BookId, $_id, $NewParameters, $quick = null)
    {
        if ($quick != null && ($quick == 1 || $quick == 0)) {
            $Parameters = [
                "edit_delete_user" => $quick,
                "edit_inherit_users" => $quick,
                "edit_edit_user" => $quick,
                "edit_add_user" => $quick,
                "edit_sever_comics_info" => $quick,
                "edit_add_project" => $quick,
            ];
        } else {
            $Parameters = $NewParameters;
        }

        $return_data = Db::table('author_and_chinese_team')
            ->where([
                "book_id" => $BookId,
                "user_id" => $UserId,
                "_id" => $_id,
            ])
            ->Update($Parameters);
        if ($return_data != 1) {
            $return_data = errorJsonReturn('The user has appeared here multiple times', '数据信息异常 请联系管理员解决');
        } else {
            $return_data = successJsonReturn();
        }
        $return_data = json_decode($return_data->getContent(), true);
        return $return_data;
    }
}
